package com.sc.study.foundation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sc.common.core.domain.entity.SysDept;
import com.sc.study.foundation.domain.ScSubjectTable;
import com.sc.study.foundation.domain.UserTreeData;
import com.sc.system.service.ISysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sc.common.annotation.Log;
import com.sc.common.core.controller.BaseController;
import com.sc.common.core.domain.AjaxResult;
import com.sc.common.enums.BusinessType;
import com.sc.study.foundation.domain.ScSubjectTeacher;
import com.sc.study.foundation.service.IScSubjectTeacherService;
import com.sc.common.utils.poi.ExcelUtil;
import com.sc.common.core.page.TableDataInfo;

/**
 * 课程授课老师Controller
 * 
 * @author sc
 * @date 2022-02-27
 */
@RestController
@RequestMapping("/study/subjectteacher")
public class ScSubjectTeacherController extends BaseController
{
    @Autowired
    private IScSubjectTeacherService scSubjectTeacherService;
    @Autowired
    private ISysDeptService sysDeptService;
    /**
     * 查询课程授课老师列表包含老师和科目
     */
    @PreAuthorize("@ss.hasPermi('study:subjectteacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScSubjectTeacher scSubjectTeacher)
    {
        startPage();
        List<ScSubjectTeacher> list = scSubjectTeacherService.selectScSubjectTeacherList(scSubjectTeacher);
        return getDataTable(list);
    }


    /**
     * 导出课程授课老师列表
     */
    @PreAuthorize("@ss.hasPermi('study:subjectteacher:export')")
    @Log(title = "课程授课老师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScSubjectTeacher scSubjectTeacher)
    {
        List<ScSubjectTeacher> list = scSubjectTeacherService.selectScSubjectTeacherList(scSubjectTeacher);
        ExcelUtil<ScSubjectTeacher> util = new ExcelUtil<ScSubjectTeacher>(ScSubjectTeacher.class);
        util.exportExcel(response, list, "课程授课老师数据");
    }

    /**
     * 获取课程授课老师详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:subjectteacher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scSubjectTeacherService.selectScSubjectTeacherById(id));
    }

    /**
     * 新增课程授课老师
     */
    @PreAuthorize("@ss.hasPermi('study:subjectteacher:add')")
    @Log(title = "课程授课老师", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScSubjectTeacher scSubjectTeacher)
    {
        return toAjax(scSubjectTeacherService.insertScSubjectTeacher(scSubjectTeacher));
    }

    /**
     * 修改课程授课老师
     */
    @PreAuthorize("@ss.hasPermi('study:subjectteacher:edit')")
    @Log(title = "课程授课老师", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScSubjectTeacher scSubjectTeacher)
    {
        return toAjax(scSubjectTeacherService.updateScSubjectTeacher(scSubjectTeacher));
    }

    /**
     * 删除课程授课老师
     */
    @PreAuthorize("@ss.hasPermi('study:subjectteacher:remove')")
    @Log(title = "课程授课老师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scSubjectTeacherService.deleteScSubjectTeacherByIds(ids));
    }


    /**
     * 获取部门下拉树列表包含老师
     */
    @PostMapping("/treeSelectIncludeTeacher")
    public AjaxResult treeSelectIncludeTeacher(@RequestBody UserTreeData userTreeData)
    {
        List<SysDept> depts = sysDeptService.selectDeptList(new SysDept());
        return AjaxResult.success(scSubjectTeacherService.buildDeptTreeSelectIncludeTeacher(depts,userTreeData.getSubId()));
    }
}
